﻿using Microsoft.AspNetCore.Mvc;
using Scm.Jwt.Util;
using Scm.Service.Dto;
using Scm.Service.Services;

namespace Scm.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class ProjectController : ControllerBase
    {

        private ProjectService _projectSrv = new();

        [HttpGet("ProjectSelector")]
        public BaseDto<List<ProjectSelectorDto>> ProjectSelector(int page, int size)
        {
            var token = Request.Headers["token"];
            if (string.IsNullOrEmpty(token)) return BaseDto<List<ProjectSelectorDto>>.ErrorMsg("未获取到 token 信息");
            var CheckResult = JWTTokenUtil.CheckToken(token);
            if (CheckResult.Code != 0) return BaseDto<List<ProjectSelectorDto>>.ErrorMsg(CheckResult?.Msg ?? "token 已失效", 401);
            return _projectSrv.AllForSelector(
                new PageDto
                {
                    Page = page,
                    Size = size
                });
        }
    }
}
